package com.formation.userbase.persistance.utils;

import java.sql.DriverManager;
import java.sql.SQLException;


public class BdConnect {

	    private static String nom_classe_du_driver;
	    private java.sql.Connection c;
	    private static String nom_base_de_donnees;
	    private static String url_de_connection_BD;
	    private static String login_BD;
	    private static String mdp_BD;

	    public void BdConnect(){
	    	//newConnexion();
	    /*	nom_base_de_donnees = "CentreDeFormation";
 	        login_BD = "root";
 	        mdp_BD = "";
 	        url_de_connection_BD = "jdbc:mysql://localhost/"+nom_base_de_donnees;
 	       this.c =  DriverManager.getConnection(url_de_connection_BD,login_BD,mdp_BD);*/
	    }
	    
	    public static void TesterPresenceDriver1()
	    {
	        System.out.println("Le TEST Est bien ex�cut�.\n");
	        try
	        {
	            Class test_jdbc_driver = Class.forName("com.mysql.jdbc.Driver");
	        }
	        catch (ClassNotFoundException ex)
	        {
	            System.out.println("attention, la classe driver mysql JDBC n'a PAS �t� charg�  !!!!!");
	            
	            // Logger.getLogger(DiplomateDeDonnees.class.getName()).log(Level.SEVERE, null, ex);
	        }
	    }
	    
	    public  java.sql.Connection getConnexion(){
	    	nom_base_de_donnees = "CentreDeFormation";
 	        login_BD = "root";
 	        mdp_BD = "";
 	        url_de_connection_BD = "jdbc:mysql://localhost/"+nom_base_de_donnees;
	    	
	    	if (this.c==null){
				System.out.println("connexion null");
	    		//newConnexion();
				


	 	        try {
					this.c =  DriverManager.getConnection(url_de_connection_BD,login_BD,mdp_BD);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	} else
				try {
					if (this.c.isClosed()){
						System.out.println("connexion ferm�");
						 try {
								this.c =  DriverManager.getConnection(url_de_connection_BD,login_BD,mdp_BD);
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	return this.c;
	    	
	    }
	    
	    
	   
	
}
